import 'package:flutter/material.dart';

class RadioGroupExample extends StatefulWidget {
  const RadioGroupExample({super.key});

  @override
  State<RadioGroupExample> createState() => _RadioGroupExampleState();
}

class _RadioGroupExampleState extends State<RadioGroupExample> {
  String? selectedValue = 'option1';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('RadioGroup Row Layout')),
      body: Padding(
        padding: EdgeInsets.all(16),
        child: Column(
          children: [
            // Solution 1: Using Flexible
            Text('Solution 1: Using Flexible'),
            Row(
              children: [
                Flexible(
                  child: RadioListTile<String>(
                    title: Text('选项1'),
                    value: 'option1',
                    groupValue: selectedValue,
                    onChanged: (value) {
                      setState(() {
                        selectedValue = value;
                      });
                    },
                  ),
                ),
                Flexible(
                  child: RadioListTile<String>(
                    title: Text('选项2'),
                    value: 'option2',
                    groupValue: selectedValue,
                    onChanged: (value) {
                      setState(() {
                        selectedValue = value;
                      });
                    },
                  ),
                ),
              ],
            ),
            
            SizedBox(height: 20),
            
            // Solution 2: Using Expanded
            Text('Solution 2: Using Expanded'),
            Row(
              children: [
                Expanded(
                  child: RadioListTile<String>(
                    title: Text('选项A'),
                    value: 'optionA',
                    groupValue: selectedValue,
                    onChanged: (value) {
                      setState(() {
                        selectedValue = value;
                      });
                    },
                  ),
                ),
                Expanded(
                  child: RadioListTile<String>(
                    title: Text('选项B'),
                    value: 'optionB',
                    groupValue: selectedValue,
                    onChanged: (value) {
                      setState(() {
                        selectedValue = value;
                      });
                    },
                  ),
                ),
              ],
            ),
            
            SizedBox(height: 20),
            
            // Solution 3: Custom Radio with Row
            Text('Solution 3: Custom Radio Layout'),
            Row(
              children: [
                Expanded(
                  child: Row(
                    children: [
                      Radio<String>(
                        value: 'custom1',
                        groupValue: selectedValue,
                        onChanged: (value) {
                          setState(() {
                            selectedValue = value;
                          });
                        },
                      ),
                      Text('自定义1'),
                    ],
                  ),
                ),
                Expanded(
                  child: Row(
                    children: [
                      Radio<String>(
                        value: 'custom2',
                        groupValue: selectedValue,
                        onChanged: (value) {
                          setState(() {
                            selectedValue = value;
                          });
                        },
                      ),
                      Text('自定义2'),
                    ],
                  ),
                ),
              ],
            ),
            
            SizedBox(height: 20),
            
            // Solution 4: Using IntrinsicWidth
            Text('Solution 4: Using IntrinsicWidth'),
            Row(
              children: [
                IntrinsicWidth(
                  child: RadioListTile<String>(
                    title: Text('紧凑1'),
                    value: 'compact1',
                    groupValue: selectedValue,
                    onChanged: (value) {
                      setState(() {
                        selectedValue = value;
                      });
                    },
                  ),
                ),
                IntrinsicWidth(
                  child: RadioListTile<String>(
                    title: Text('紧凑2'),
                    value: 'compact2',
                    groupValue: selectedValue,
                    onChanged: (value) {
                      setState(() {
                        selectedValue = value;
                      });
                    },
                  ),
                ),
              ],
            ),
            
            SizedBox(height: 20),
            
            // Current Selection Display
            Container(
              padding: EdgeInsets.all(16),
              decoration: BoxDecoration(
                color: Colors.blue.shade50,
                borderRadius: BorderRadius.circular(8),
              ),
              child: Text(
                '当前选择: ${selectedValue ?? '无'}',
                style: TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}